// ----------------------------------------
// Filename: TSensor.h
// Description: Routines to implement an I2C Temperature Sensor
// Author: Anton Jatmiko
// Date: 20 April 2014

#ifndef TSENSOR_H
#define	TSENSOR_H

#include <xc.h>
#include "types.h"
#include "I2C.h"

// ----------------------------------------
// TSensor_Init
//
// Initialize temperature sensor
// Input:
//   none
// Output:
//   none
// Conditions:
//   none
void TSensor_Init(void);

// ----------------------------------------
// TSensor_ReadStarted
//
// Start reading temperature value from the sensor
// Input:
//   start is a boolean indicating whether to start or stop the reading
// Output:
//   TRUE if read is started successfully
// Conditions:
//   assume temperature register has been read or preset
BOOL TSensor_ReadStarted(BOOL start);

// ----------------------------------------
// TSensor_ReadExecuting
//
// Start reading temperature value from the sensor
// Input:
//   readStarted is a boolean indicating whether or not read has been started
//   dataObtained is a pointer to data obtained flag
//   dataMSB is a pointer to the MSB temperature value
//   dataLSB is a pointer to the LSB temperature value
// Output:
//   TRUE if read is still in progress
// Conditions:
//   assume temperature register has been read or preset
BOOL TSensor_ReadExecuting(BOOL readStarted, BOOL * const dataObtainedPtr, UINT8 * const dataMSBPtr, UINT8 * const dataLSBPtr);

// ----------------------------------------
// TSensor_ReadExecuting
//
// Convert the raw data to milli Celcius
// Input:
//   rawData is the data read from the sensor
//   dataObtained is a pointer to data obtained flag
// Output:
//   temperature value in milli Celcius
// Conditions:
//   none
INT32 TSensor_Raw2MilliCelc(TUINT16 rawData, BOOL * const dataObtainedPtr);

#endif